import sun.net.idn.Punycode;

import java.time.Period;

class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(int data) {
        this.val = data;
        this.left = null;
        this.right = null;
    }


}

public class BinaryTreeTraversalRecursion {
    //先序遍历
    public static void preOrder(TreeNode head) {
        if(head == null) {
            return;
        }
        System.out.print(head.val + " ");
        preOrder(head.left);
        preOrder(head.right);
    }

    //中序遍历
    public static void inOrder(TreeNode head) {
        if(head == null) {
            return;
        }
        preOrder(head.left);
        System.out.print(head.val + " ");
        preOrder(head.right);
    }
    //后序遍历
    public static void posOrder(TreeNode head) {
        if(head == null) {
            return;
        }
        preOrder(head.left);
        preOrder(head.right);
        System.out.print(head.val + " ");
    }
    public static void main(String[] args) {
        TreeNode head = new TreeNode(1);
        head.left = new TreeNode(2);
        head.right = new TreeNode(3);
        head.left.left = new TreeNode(4);
        head.left.right = new TreeNode(5);
        head.right.left = new TreeNode(6);
        head.right.right = new TreeNode(7);

        //先序遍历
        System.out.print("先序遍历： ");
        preOrder(head);
        System.out.println();
        //中序遍历
        System.out.print("中序遍历： ");
        inOrder(head);
        System.out.println();
        //后序遍历
        System.out.print("后序遍历： ");
        posOrder(head);
        System.out.println();

    }
}
